package com.trkj.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.DeptDAO;
import com.trkj.dao.EmpDAO;
import com.trkj.dao.NoticeDAO;
import com.trkj.pojo.Emp;
import com.trkj.pojo.Notice;
import com.trkj.vo.NoticeVo;

/**
 * 通知申请Service
 * @author 彭帅
 *
 */
@Service
@Transactional
public class NoticeService {
	@Autowired
	EmpDAO empDAO;
	@Autowired
	DeptDAO deptDAO;
	@Autowired
	NoticeDAO noticeDAO;
	public NoticeVo noticeVo(Integer empid) {
		try {
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
			Emp emp = empDAO.findOne(empid);
			NoticeVo noticeVo = new NoticeVo();
			noticeVo.setEmpId(emp.getEmpId());
			noticeVo.setEmpName(emp.getEmpName());
			noticeVo.setDeptName(emp.getDept().getDeptName());
			Date date = simpleDateFormat.parse(simpleDateFormat.format(new Date()));
			int a = date.getYear()+1900;
			int b = date.getMonth()+1;
			int c = date.getDate();
			noticeVo.setNoticeUptime(a+"-"+b+"-"+c);
			noticeVo.setLunchPeople(emp.getEmpId());
			return noticeVo;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 保存通知申请
	 * @param notice 通知实体
	 * @param empId 登录员工编号
	 * @return
	 */
	public Integer save_notice(Notice notice,Integer empId) {
		try {
			if (notice != null) {
				if (empId != null) {
					Emp emp = empDAO.findOne(empId);
					notice.setEmp(emp);
				}
				return noticeDAO.save(notice).getNoticeId();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
}
